package UI;

import java.util.Scanner;
public class MainUI
{
    private AddressUI addressUI;
    private DVDUI dvdUI;
    private LoanUI loanUI;
    private static MainUI instance = null;
    private boolean exit = false;
    
    // single menu
    private MainUI()
    {
         mainMenuStart();
         dvdUI.getInstance();
         loanUI.getInstance();
         addressUI.getInstance();
    }
    
    public static MainUI getInstance()
    {
        if(instance == null)
        {
            instance = new MainUI();
        }
        return instance;
    }
    
    // choose a menu to go
    public void mainMenuStart()
    {
        
        {
            while(!exit)
            {
                exit = false;
                int choice = printMainMenu();
                switch (choice)
                {
                        case 1: startAddressMenu();
                            break;
                        case 2: startDvdMenu();
                            break;
                        case 3: startLoanMenu();

                            break;
                        case 4: exit();
                            break;
                
                }
            }
        }
    }

    // prints main menu
    public int printMainMenu()
    {
        Scanner keyboard = new Scanner(System.in);
        System.out.print('\f');
        System.out.println("*** Main Menu ***");
        System.out.println("1. Address Menu");
        System.out.println("2. DVD Menu");
        System.out.println("3. Loan Menu");
        System.out.println("4. Quit");
        System.out.println("Your choice #: ");
        
        int choice = keyboard.nextInt();
        return choice; 
    }
    
    // calling other menus
    public void startAddressMenu()
    {
        System.out.print('\f');
        addressUI.getInstance().addressMenuStart();
    }
    
    public void startDvdMenu()
    {
        System.out.print('\f');
        dvdUI.getInstance().DVDMenuStart();
    }
    
    public void startLoanMenu()
    {
        System.out.print('\f');
        loanUI.getInstance().loanMenuStart();
    }
    
    // quiting the program
    public void exit()
    {
        System.exit(1);
    }
}